#include "mainwindow.h"
#include "ui_mainwindow.h"
//#include "qmeta/image.h"


MainWindow::MainWindow(QWidget *parent) :
   QMainWindow(parent),
   ui(new Ui::MainWindow)
{
   ui->setupUi(this);
   loadFileList();
   currentPicture = files.begin();
   setImage();
}

MainWindow::~MainWindow()
{
   delete ui;
}

void MainWindow::loadFileList()
{
   QDir dir(ui->pathEdit->text());
   files = dir.entryInfoList(QStringList("*.jpg"), QDir::Files);
}

void MainWindow::setImage()
{
   QPixmap picture(currentPicture->absoluteFilePath());
   ui->initialImage->setPixmap(picture);
   ui->resultLabel->setText(getText());
}

void MainWindow::on_nextButton_clicked()
{
   if (currentPicture != --files.end())
   {
      ++currentPicture;
      setImage();
   }
}

void MainWindow::on_prevButton_clicked()
{
   if (currentPicture != files.begin())
   {
      --currentPicture;
      setImage();
   }
}

void MainWindow::on_reloadFilesButton_clicked()
{
    loadFileList();
}

QString MainWindow::getText()
{
//   qmeta::Image imageInfo(currentPicture->absoluteFilePath());
//   if (imageInfo.IsValid())
//   {
//      if (imageInfo.iptc())
//      {
//         return *imageInfo.iptc()->Values(qmeta::Iptc::kKeywords).begin();
//      }
//   }
      return "test";

}


